package com.sphd.emanu.activity.vip;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;

import com.sphd.emanu.R;
import com.sphd.emanu.adapter.MyViewPagerAdapter;
import com.sphd.emanu.config.Constant;
import com.sphd.emanu.fragment.vip.VipFragment;
import com.sphd.emanu.interfaces.MemberCountCallBack;
import com.sphd.emanu.mvp.MVPBaseActivity;
import com.sphd.emanu.pojo.vip.MemberCount;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 会员模块
 *
 * @Author Hu
 * @Time 2017/5/16 -- 9:38.
 * @Email 87683202@qq.com
 */
public class VipActivity extends MVPBaseActivity<VipContract.View, VipPresenter> implements VipContract.View,
        MemberCountCallBack {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tabs)
    TabLayout tabs;
    @BindView(R.id.my_vp)
    ViewPager myVp;
    MyViewPagerAdapter myViewPagerAdapter;
    List<Fragment> fragmentList;
    String[] titles = {"今日新增\n2", "本月新增\n2", "全部会员\n2"};
    Intent intent;
    Bundle bundle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vip);
        ButterKnife.bind(this);
        initView();
        initEvent();
    }

    private void initEvent() {
        toolbar.setNavigationOnClickListener(v -> finish());
    }

    private void initView() {
        setTitleBar(toolbar, "会员");
        intent = getIntent();
        bundle = intent.getExtras();
        fragmentList = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            VipFragment vipFragment = new VipFragment();
           vipFragment.setType(i+1);
            vipFragment.setMemberCountCallBack(this);
            vipFragment.setArguments(bundle);
            fragmentList.add(vipFragment);
        }

        myViewPagerAdapter = new MyViewPagerAdapter(context, getSupportFragmentManager(), fragmentList, titles);
        myVp.setAdapter(myViewPagerAdapter);
        tabs.setupWithViewPager(myVp);
    }

    @Override
    public void callBackCount(MemberCount memberCount) {
        titles[0]="今日新增\n"+memberCount.getDayCount();
        titles[1]="本月新增\n"+memberCount.getMonthCount();
        titles[2]="全部会员\n"+memberCount.getAllCount();
        myViewPagerAdapter.notifyDataSetChanged();
    }


}
